package com.linkage.jz.bankruptcy.activity.Project.ZQUser;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Project.ApplyProNoticeActivity;
import com.linkage.jz.bankruptcy.activity.Project.CreateProjectDetailActivity;
import com.linkage.jz.bankruptcy.activity.RegistLogin.GetPwdOneActivity;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.ContactInfo;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.bean.ObjValInfo;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.bean.ZQUserInfo;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.net.ToastUtil;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.SignUtil;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.seapeak.view.QuickUserPopView;

import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Random;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * A login screen that offers login via email/password.
 */
public  class CreateZQOneProjectActivity extends BaseCreateActivity implements OnClickListener{
    private static final String TAG = CreateZQOneProjectActivity.class.getSimpleName();
    private static ZQUserDetailBaseInfo mInfo ;
    private static ShapeLoadingDialog shapeLoadingDialog ;
    private TextView popClick;
    @Override
    public void initData() {

    }

    @Override
    public void setListener() {
//        btn_login.setOnClickListener(this);
        top_back.setOnClickListener(this);
//        ll_phonelogin.setOnClickListener(this);


    }

    @Override
    public void initTitle() {
        top_title = findViewById(R.id.top_title);
        top_title.setText("选择债权人身份类型");
        top_mune = findViewById(R.id.top_mune);
        top_mune.setVisibility(View.INVISIBLE);
    }

    @Override
    public void initView() {
        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
//        btn_login = findViewById(R.id.btn_login);
        top_back = findViewById(R.id.top_back);
        top_mune = findViewById(R.id.top_mune);
        ll_jgzqr = findViewById(R.id.ll_jgzqr);
        top_title = findViewById(R.id.top_title);
        ck_remember = findViewById(R.id.ck_remember);
        ll_zrzqr = findViewById(R.id.ll_zrzqr);
        ll_swjg = findViewById(R.id.ll_swjg);
        ll_jgzqr.setOnClickListener(this);
        ll_zrzqr.setOnClickListener(this);
        ll_swjg.setOnClickListener(this);

    }

    ImageView mLeftLogo;
    ImageView mRightLogo;
    EditText et_username;
    EditText et_password;
    Button btn_login;
    TextView top_title,getPwd;
    Button top_back,top_mune;
    CheckBox ck_remember;
    LinearLayout ll_jgzqr,ll_zrzqr,ll_swjg;
    static String mProId;
    private static String mUserid;
    private static String mUsername;
    private static String mPhone;

    public static void start(Context context,ZQUserDetailBaseInfo info,String userid,String username,String phone) {
        mInfo = info;
        mUserid = userid;
        mUsername = username;
        mPhone = phone;
        Intent intent = new Intent(context, CreateZQOneProjectActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_create_zq_one);
        super.onCreate(savedInstanceState);

        initview();

//        String user = SPUtils.getInstance(Consts.SPNAME).getString("loginUser");
//        String pwd = SPUtils.getInstance(Consts.SPNAME).getString("loginPwd");
//
//        if(!user.equalsIgnoreCase(""))
//        {
//            et_username.setText(user);
//            et_password.setText(pwd);
//        }
        shapeLoadingDialog = new ShapeLoadingDialog(this);



    }

    //初始化视图
    private void initview() {
        //登录层、下拉层、其它登录方式层

        top_back = findViewById(R.id.top_back);
        top_mune = findViewById(R.id.top_mune);
        ll_jgzqr = findViewById(R.id.ll_charger);
        top_title = findViewById(R.id.top_title);
        ck_remember = findViewById(R.id.ck_remember);
        ll_zrzqr = findViewById(R.id.ll_admin);
        ll_swjg = findViewById(R.id.ll_swjg);

        popClick = findViewById(R.id.pop_click);
        /**
         * 弹窗
         */
        popClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //等参数
                getProjetContact();
//                QuickUserPopView.show(CreateZQOneProjectActivity.this,mUserid,mProId,mUsername,mPhone);
            }
        });

    }

    @Override
    public void onClick(View view) {


            switch (view.getId()) {
                case R.id.ll_jgzqr:

                 CreateZQTwoProjectActivity.start(this,"0",mInfo,mUserid,mUsername,mPhone);
                    finish();
                    break;
                case R.id.ll_zrzqr:
                    CreateZQTwoProjectActivity.start(this,"1",mInfo,mUserid,mUsername,mPhone);
                    finish();
                    break;
                case R.id.ll_swjg:
//                    CreateZQTwoProjectActivity.start(this,"2");

                    ObjValInfo tmpBig = new ObjValInfo();
                    ObjValInfo tmpSmall = new ObjValInfo();
                    mInfo.setIdentityBigTypes(tmpBig);
                    mInfo.setIdentitySmallTypes(tmpSmall);
                    mInfo.getIdentityBigTypes().setValue("2");
//                    mInfo.setId(BankruptcyApp.loginInfo.getId());
                    BankruptcyApp.mphone = mPhone;
                    BankruptcyApp.mUserid =mUserid;
                    BankruptcyApp.mUsername = mUsername;
                    EditZQUserBaseInfoActivity.start(this, mInfo, 1, 0,true);
                    finish();
                    break;
                case R.id.top_back:
                    finish();
                    break;

                default:
                    break;
            }


    }



    public void getProjetContact() {

        Observable<JsonObject> observable;

        observable = Network
                .getAPIService()
                .getProjetContact(getUserToken(), mInfo.getBankruptcyProjectId());


        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {

                        int code = json.get("code").getAsInt();

                        if(code == 0)
                        {
                            ContactInfo info = new Gson().fromJson(json.getAsJsonObject("data"),ContactInfo.class);
                            if(info!=null)
                                QuickUserPopView.show(CreateZQOneProjectActivity.this,info.getSysUserId(),mInfo.getBankruptcyProjectId(),info.getName(),info.getMobile());
                        }else
                        {
                            ToastUtil.showShort(json.get("msg").getAsString());

                        }
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {

                        super.onError(e);
                    }
                });
    }


}

